package com.sikiedu.logindemo.controller;

import com.sikiedu.logindemo.domain.User;
import com.sikiedu.logindemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    public String register(User user){
        System.out.println(user);
        userService.save(user);

        return "redirect:/index";
    }

    @RequestMapping("/login")
    public String login(User user){
        System.out.println(user);
        boolean success=userService.findUser(user);
        if(success){
            return "success.html";
        }else{
            return "redirect:/index";
        }
    }
}
